package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.UserService;

@RestController
@RequestMapping("/api/user")
public class UserController {

    private UserService userService;

    @Autowired
    public void autowiredService(UserService userService){
        this.userService = userService;
    }

    /**
     * 通过uid获取user
     * @param uid user id
     */
    @RequestMapping("/{uid}")
    public Result getUser(@PathVariable int uid, HttpServletRequest request, HttpServletResponse response){
        return userService.getUser(uid, request, response);
    }

    @RequestMapping("/delete/{uid}")
    public Result deleteUser(@PathVariable int uid, HttpServletRequest request, HttpServletResponse response){
        return userService.deleteUser(uid, request, response);
    }

    /**
     * 获取所有User
     */
    @RequestMapping("/all")
    public Result getAllUser(HttpServletRequest request, HttpServletResponse response){
        return userService.getAllUser(request, response);
    }

    /**
     * 修改用户信息
     */
    @RequestMapping("/update")
    public Result updateUser(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return userService.updateUser(data, request, response);
    }

    /**
     * 添加用户
     */
    @RequestMapping("/add")
    public Result addUsers(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return userService.addUsers(data, request, response);
    }

    /**
     * 获取job target user
     */
    @RequestMapping("/jobtarget/{jid}")
    public Result getJobTargetUser(@PathVariable int jid, HttpServletRequest request, HttpServletResponse response){
        return userService.getJobTargetUser(jid, request, response);
    }

    /**
     * 获取用户task
     */
    @RequestMapping("/task")
    public Result getUserTask(HttpServletRequest request, HttpServletResponse response){
        return userService.getUserTask(request, response);
    }

    /**
     * 获取paper
     */
    @RequestMapping("/paper/{id}")
    public Result getPaper(@PathVariable int id, HttpServletRequest request, HttpServletResponse response){
        return userService.getPaper(id, request, response);
    }

    @RequestMapping("/check/user")
    public Result checkUser(HttpServletRequest request, HttpServletResponse response){
        return userService.checkUser(request, response);
    }

    @RequestMapping("/check/admin")
    public Result checkAdmin(HttpServletRequest request, HttpServletResponse response){
        return userService.checkAdmin(request, response);
    }

}
